/*****************
Class Geometry : public Spatial

*This class defines a polygon with predefined vertex types and is derived from Spatial.

Setting up to rendering procedure:
1. Initialize(...);
2. addVertex(...);
3. setup(...);

*Use getVertices(); to get a copy of the vertices as a float3 vector to use for collisions etc.

IMPORTANT: Geometry class should NOT be used as a grouping point on the scene.
******************/

#ifndef GRAPHICS__GEOMETRY_H_
#define GRAPHICS__GEOMETRY_H_

#include "Spatial.h"
#include "Renderer.h"
#include "Vertex.h"

using namespace poly;

namespace graphics
{

class Renderer;

class Geometry : public Spatial
{
public:
	Geometry();
	~Geometry();

	/**
	 * Draws the current Geometry using the Renderer.
	 * Better idea is to attach the Geometry to a node and call it.
	 */
	virtual void Draw(Renderer&);

/*===================================================================================*/
/*GEOMETRY PROPERTIES*/
/*===================================================================================*/
private:
	/**
	 * D3DDevice interface.
	 */
	D3DDevice				m_Device;

	/**
	 * Vertex buffer interface.
	 */
	IDirect3DVertexBuffer9* m_VertexBuffer;

	/**
	 * Vertex type.
	 */
	int						m_VertexType;

	/**
	 * Copy of raw vertices (only position information)
	 */
	std::vector<float3>		V_Vertices;
public:
	/**
	 * Vector of V_P
	 */
	std::vector<V_P>		V_Vector_P;
	/**
	 * Vector of V_PC
	 */
	std::vector<V_PC>		V_Vector_PC;
	/**
	 * Vector of V_PT
	 */
	std::vector<V_PT>		V_Vector_PT;
	/**
	 * Texture of the Geometry
	 */
	IDirect3DTexture9*      P_Texture;

	/**
	 * Has to be called prior to any other function call.
	 */
	void Initialize(D3DDevice);

	/**
	 * Adds a vertex to the geometry
	 * @param Position of the vertex.
	 */
	void addVertex(float3 position);
	/**
	 * Adds a vertex to the geometry
	 * @param Position of the vertex. 
	 * @param Color of the vertex.
	 */
	void addVertex(float3 position,float3 color);
	/**
	 * Adds a vertex to the geometry
	 * @param Texture coordinates (u,v) of the vertex. 
	 */
	void addVertex(float3 position,float2 texture);

	/**
	 * Applies a texture from file.
	 * Supported file formats: .bmp, .dds, .dib, .hdr, .jpg, .pfm, .png, .ppm, .tga
	 * @param Filename.
	 */
	void applyTexture(char* filename);

	/**
	 * Call this after done setting up (applyTexture and such) Geometry.
	 */
	void setup();

	/**
	 * @return Raw vertex set.
	 */
	std::vector<float3>		getVertices();
	/**
	 * @return Vertex buffer pointer.
	 */
	IDirect3DVertexBuffer9* getVertexBuffer();
	/**
	 * @return Vertex type.
	 */
	int						getVertexType();

	/**
	 * For backwards compatibility.
	 * @return Old polygon format. Can be used to merge with collision tests and such.
	 */
	poly::Polygon			getPolygon();

};

}/* namespace graphics */
#endif /*GRAPHICS__GEOMETRY_H_*/